home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Directorty Opus 5 - Magellan
/
Opus 5 - Magellan.iso
/
Extras
/
DOpusLhARexx2
/
ARexx
/
AddFilesLhA.rexx
next >
Wrap
OS/2 REXX Batch file
|
1994-07-01
|
9KB
|
426 lines
/*rx
*
* AddFilesLhA.rexx - Add the selected files to an LhA archive previously
* listed in a DOpus window by ListLha.rexx.
*
* $VER: AddFilesLhA 40.7 (23/05/94) by Geoff Seeley
*
* Usage: ARexx command AddFilesLhA.rexx (from DOpus)
*
*/
/* configuration variables (change these to suit your setup) */
LhaCommand = 'XFH_Work:C/Archivers/File/LhA '
OutputWindow = '>CON:30/145/640/100/LhA_Output/CLOSE/SCREENDOPUS.1 '
InputWindow = '<CON:30/245/640/50/LhA_Input/AUTO/SCREENDOPUS.1 '
AddList = 'T:lha_file_list'
ListLhARexx = "RX DOpus:ARexx/ListLhA.rexx"
/*---------------------------------------------------------------------------*/
/* misc. variables */
DOpusPort = 'DOPUS.1'
LhaAddCmd = ''
LhaAddBase = '-m a '
LhaRecurse = '-r '
LhaSavePath = '-x '
CreateNew = 0
AddSubDirs = 0
if ~show(l,"rexxsupport.library") then
call addlib("rexxsupport.library",0,-30,0)
/* make sure we've got somebody to talk to */
if showlist('Ports', DOpusPort) = 0 then do
say 'Directory Opus ARexx port not found. Aborting.'
call CleanUp
end
/* make sure the right task is listening... */
address 'DOPUS.1'
options results
TopText "Adding File(s) to an LhA Archive"
Busy on
/* get the path/name of the LhA archive file */
'Status 14 -1'
LhaArchive = result
/* if this isn't an LhA buffer, try the other window then ask for new arc. */
if (IsLhAFile(LhaArchive) = 0) then do
/* Hmm, let's try the other window */
OtherWindow
'Status 14 -1'
LhaArchive = result
/* if neither window looks right, look for selected file */
if (IsLhAFile(LhaArchive) = 0) then do
'GetNextSelected -1'
LhaArchive = RESULT
if LhaArchive ~= 0 & IsLhaFile(LhaArchive) then do
call SetYesNo
Request "Add files to selected archive? ("||LhaArchive||")"
UseArchive = RESULT
Busy on
call RestoreRequester
if UseArchive = 1 then do
'Status 13 -1'
LhaPath = Result
LhaArchive = LhaPath || LhaArchive
address COMMAND ListLhARexx
end
else do
OtherWindow
TopText "Adding files to LhA archive aborted."
call CleanUp
end
end
else do
call SetYesNo
Request "No LhA archive listed. Do you wish to create one?"
if Result = 0 then do
OtherWindow
TopText "Adding files to LhA archive aborted."
call CleanUp
end
else
CreateNew = 1
call RestoreRequester
/* get path of window */
'Status 13 -1'
LhaPath = Result
/* get new archive */
GetString "'Enter LhA Archive Name: (Path: '"||LhaPath||"')'"
LhaArchive = Result
/* cancel it? */
if RC = 1 then do
TopText "LhA archive creation aborted."
call CleanUp
end
if (IsLhAFile(LhaArchive) = 0) then
LhaArchive = LhaArchive || ".lha"
NewLhaArchive = LhaArchive
LhaArchive = LhaPath || LhaArchive
end
end
else do
/* get path to archive */
call FindLhAPath
LhaArchive = LhaPath || LhaArchive
end
end
else do
/* make sure we don't have *two* LhA buffers */
OtherWindow
'Status 14 -1'
if (IsLhAFile(result) = 1) then do
Notify "Sorry, You have two LhA archives listed.\Cannot add files from LhA archive."
OtherWindow
call CleanUp
end
OtherWindow
/* get path to archive */
call FindLhAPath
LhaArchive = LhaPath || LhaArchive
end
/* check for existance of archive */
if CreateNew = 0 then do
if ~exists(LhaArchive) then do
Notify "Can't seem to find '" || LhaArchive || "'\Aborting."
call CleanUp
end
end
/* switch to window with files to add... */
OtherWindow
/* get list of selected entries */
'GetSelectedAll "|" -1'
SelectedEntries = result
/* must select *something* man... */
if SelectedEntries = 'RESULT' then do
Notify "Please select file(s) to add first..."
call CleanUp
end
NumberOfEntries = CountWords(SelectedEntries)
/* get source directory */
'Status 13 -1'
SrcDir = result
/* verify, (I think I'm paranoid :-) */
if SrcDir = 'RESULT' | SrcDir = "" then do
Notify "Unable to get source directory. Aborting."
call CleanUp
end
/* ask user if they want the path included */
call SetYesNo
Request "Store pathname(s) of selected file(s) in LhA archive?"
StorePath = Result
Request "Add any possible subdirectories?"
AddSubDirs = Result
call RestoreRequester
/* form proper command */
LhaAddCmd = LhaAddBase
if StorePath = 1 then do
LhaAddCmd = LhaSavePath || LhaAddCmd
end
if AddSubDirs = 1 then do
LhaAddCmd = LhaRecurse || LhaAddCmd
end
/* add the files */
call AddFileList
/* go back to the archive window */
OtherWindow
if CreateNew = 0 then do
/* call ListLhA to re-list the LhA archive in the window */
address command ListLhARexx
end
else do
/* rescan the directory */
'Rescan -1'
/* select the new archive and list it in the window */
'Select '|| NewLhaArchive || ' onlyfiles name'
address command ListLhARexx
end
TopText "Finished adding selected file(s) to LhA archive."
call CleanUp
exit
/*---------------------------------------------------------------------------*/
AddFileList: /* build a list of selected files, add list */
/* toast possible old list */
if exists(AddList) then
delete(AddList)
if ~open(FileList, AddList, 'W') then do
Notify "Can't open file " || AddList
call CleanUp
end
TopText "Creating file(s) list..."
do EntryNumber = 1 to NumberOfEntries
Entry = GetWord(EntryNumber, SelectedEntries)
File = Quote(Entry)
ScrollToShow Entry
call ReplaceMetaChars
writeln(FileList, File)
end
close(FileList)
TopText "Adding file(s) to LhA archive..."
/* move into source directory */
pragma(D, SrcDir)
CliCommand = LhaCommand || OutputWindow || InputWindow || LhaAddCmd ||Quote(LhaArchive)
CliCommand = CliCommand || ' @' || AddList
address command CliCommand
return
/*---------------------------------------------------------------------------*/
SetYesNo: /* set requester strings */
'Status 26 set Yes'
'Status 27 set No'
return
/*---------------------------------------------------------------------------*/
RestoreRequester: /* restore (default) requester strings */
Busy On
'Status 26 set Okay'
'Status 27 set Cancel'
return
/*---------------------------------------------------------------------------*/
ReplaceMetaChars: /* replace special wildcards with ? */
File = translate(File, '???', '()`', '?')
return
/*---------------------------------------------------------------------------*/
Quote: procedure /* add quotes to string */
parse arg string
return '"'||string||'"'
/*---------------------------------------------------------------------------*/
StripQuotes: procedure /* strip quotes from string */
parse arg string
return strip(string,, '"')
/*---------------------------------------------------------------------------*/
IsLhAFile: procedure /* look at extension, return 1 if right, else 0 */
parse arg AFileName
lps = lastpos(".", AFileName)
if lps = 0 then
return 0
FileExt = upper(right(AFileName,length(AFileName)-lps))
if FileExt ~= "LHA" & FileExt ~= "LZH" then
return 0
else
return 1
return 0
/*--------------------------------------------------------------------------*/
FindLhAPath: /* grab invisible file path to archive */
/* find number of entries, path is the last one */
'Status 6 -1'
GetEntry Result
LhaPath = Result
return
/*--------------------------------------------------------------------------*/
GetWord: procedure /* get word from '|' separated string */
parse arg number,words
if(left(words,1) ~= '|') then
words = '|'||words
do i=1 to number
idx = index(words, '|');
words = substr(words, idx+1)
end
end = index(words, '|') - 1
if words = "" then
return ""
ret_str = substr(words, 1, end)
return ret_str
/*--------------------------------------------------------------------------*/
CountWords: procedure /* count words from '|' separated string */
parse arg words
count = 0
idx = index(words, '|')
do while idx ~= 0
count = count + 1
words = substr(words, idx+1)
idx = index(words, '|')
end
return count
/*--------------------------------------------------------------------------*/
CleanUp: /* clean up files and exit */
if exists(AddList) then
delete(AddList)
Busy off
exit
return